﻿#!/usr/bin/python
 #coding: utf-8

import xlsxwriter
#创建一个新的xlsx文件(如果原有同名文件会被覆盖)
workbook = xlsxwriter.Workbook("Expenses01.xlsx")
#创建一个新的表单，默认名称为 “sheet1”，输入字符参数可指定名称
worksheet = workbook.add_worksheet()
expenses = (
    ['Rent', 1000],
    ['Gas' ,  100],
    ['Food',  300],
    ['Gym' ,   50],
)
#worksheet 默认是从0行、0列开始计数
row = 0
col = 0
#worksheet.write 方法将数据写入 xlsx 表格中
#参数依次为：行号、列号、数据、[格式]
for item, cost in (expenses):
    worksheet.write(row, col ,    item)
    worksheet.write(row, col + 1, cost)
    row += 1
#显式关闭workbook，若不显式指定，则作用域结束后自动关闭
workbook.close()